package cn.bdqn.controller;


import cn.bdqn.dao.GradeDaok;
import cn.bdqn.dao.TestDaok;
import cn.bdqn.pojo.Bank;
import cn.bdqn.pojo.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: 苏闻君
 * @Date: Created in 2020/6/23  20:06
 */
@Controller
public class TestController {
@Autowired
TestDaok testDao;
@Autowired
    GradeDaok gradeDaok;
    /**
     * 试卷查询全部,并且是否交卷
     * @param model
     * @return
     */
    @RequestMapping("/shijuan")
    public String test(Model model, HttpServletRequest request, HttpSession session){
        String scores= request.getParameter("score");
        if(scores!=null){
            Integer score=Integer.parseInt(scores);
            Integer id= (Integer) session.getAttribute("id");
            System.out.println("******************id"+id);
            gradeDaok.addGrade(id,score);
        }
        List<Test> list=testDao.list();
        model.addAttribute("list",list);
        return "shijuan";
    }

    /**
     * 查询相对应试卷的所有试题
     * @param model
     * @param id
     * @param request
     * @return
     */
    @RequestMapping("/kao")
    public String kao(Model model, Integer id, HttpServletRequest request){
        List<Bank> list=testDao.test(id);
        List<Bank> list1=testDao.testMore(id);
        id=Integer.parseInt(request.getParameter("id"));
        model.addAttribute("list",list);
        model.addAttribute("lists",list1);

        return "kao";
    }
}
